package com.uit.smarttool.ultility;

import java.util.ArrayList;
import java.util.List;

import org.ksoap2.SoapEnvelope;
import org.ksoap2.serialization.PropertyInfo;
import org.ksoap2.serialization.SoapObject;
import org.ksoap2.serialization.SoapSerializationEnvelope;
import org.ksoap2.transport.AndroidHttpTransport;
import org.ksoap2.transport.HttpTransportSE;

import com.uit.smarttool.dto.CT_GioHang;
import com.uit.smarttool.dto.DanhSachSanPham;
import com.uit.smarttool.dto.DanhSachTheCao;
import com.uit.smarttool.dto.KhachHang;
import com.uit.smarttool.dto.SanPham;

public class CallSoap {

	public final String SOAP_ACTION = "http://tempuri.org/getDSSanPham";

	public final String OPERATION_NAME = "getDSSanPham";

	public final String WSDL_TARGET_NAMESPACE = "http://tempuri.org/";

	public final String SOAP_ADDRESS = "http://supermarttool.somee.com/Service.asmx";
	
	public static int slbg;

	// CÃ¡i nÃ y chá»©a table cá»§a dataset tráº£ vá»� thÃ´ng
	SoapObject table = null;

	SoapObject client = null;

	// Chá»©a hÃ ng cá»§a báº£ng
	SoapObject tableRow = null;

	// Chá»©a ná»™i dung XML cá»§a dataset
	SoapObject responseBody = null;

	// cÃ¡i nÃ y Ä‘á»ƒ gá»�i webservice
	AndroidHttpTransport transport = null;
	SoapSerializationEnvelope sse = null;

	SanPham sanpham = new SanPham();
	public ArrayList<String> tenloaisp;
	public static ArrayList<CT_GioHang> ct_giohangList;

	public CallSoap() {

	}

	// demo
	public SanPham getallSanPham() {

		sse = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		sse.addMapping(WSDL_TARGET_NAMESPACE, "ConnectWebService",
				this.getClass());
		// chÃº Ã½ náº¿u class(á»Ÿ trÃªn Ä‘áº§u Ã­) ko pháº£i lÃ  phim thÃ¬
		// Ä‘á»•i
		sse.dotNet = true; // .NET thÃ¬ chá»�n true
		AndroidHttpTransport androidHttpTransport = new AndroidHttpTransport(
				SOAP_ADDRESS);

		try {
			client = new SoapObject(WSDL_TARGET_NAMESPACE, OPERATION_NAME);
			sse.setOutputSoapObject(client);
			sse.bodyOut = client;
			androidHttpTransport.call(SOAP_ACTION, sse);

			// bÆ°á»›c nÃ y láº¥y cáº£ file XML
			responseBody = (SoapObject) sse.getResponse();
			// bÆ°á»›c nÃ y bá»� cÃ¡c thÃ´ng tin XML chá»‰ láº¥y káº¿t quáº£
			// tráº£ vá»�
			responseBody = (SoapObject) responseBody.getProperty(1);
			// Láº¥y thÃ´ng tin XML cá»§a báº£ng tráº£ vá»�
			table = (SoapObject) responseBody.getProperty(0);
			// á»ž Ä‘Ã¢y láº¥y thÃ´ng tin tá»«ng dÃ²ng cá»§a table, báº¡n chÃº
			// Ã½ 0 lÃ  dÃ²ng Ä‘áº§u
			// tiÃªn
			tableRow = (SoapObject) table.getProperty(2);
			sanpham.setMaSP(tableRow.getProperty("MaSP").toString());
			sanpham.setTenSP(tableRow.getProperty("TenSP").toString());
			sanpham.setDonGia(tableRow.getProperty("DonGia").toString());
			sanpham.setGioiThieu(tableRow.getProperty("GioiThieu").toString());
			sanpham.setSoLuongTon(tableRow.getProperty("SoLuongTon").toString());
			sanpham.setTenDVT(tableRow.getProperty("TenDVT").toString());
			sanpham.setTenLoaiSP(tableRow.getProperty("TenLoaiSP").toString());

			return sanpham;

		} catch (Exception e) {
			sanpham.setTenSP("Loi dfg");
			sanpham.setMaSP(String.valueOf(tableRow.getPropertyCount()));
			return sanpham;
		}
	}
	
	public List<SanPham> getDanhSachSanPhamTheoMuc(int maLoaiSP) {

		
		List<SanPham> result = new ArrayList<SanPham>();
		
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"getSanPhamByDanhMuc");
		request.addProperty("MaLoaiSP", maLoaiSP);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;

		try {
			
			httpTransport.call("http://tempuri.org/getSanPhamByDanhMuc", envelope);
			response = (SoapObject) envelope.getResponse();
			response = (SoapObject) response.getProperty(1);
			table = (SoapObject) response.getProperty(0);

			slbg = table.getPropertyCount();

			for (int i = 0; i < slbg; i++)
			{
				SanPham item = new SanPham();				
				tableRow = (SoapObject) table.getProperty(i);
				if(!tableRow.getProperty("TenSP").toString().equals("Mặc định"))
				{
					item.setMaSP(tableRow.getProperty("MaSP").toString());
					item.setTenSP(tableRow.getProperty("TenSP").toString());
					item.setSoLuongTon(tableRow.getProperty("SoLuongTon").toString());
					item.setGioiThieu(tableRow.getProperty("GioiThieu").toString());
					item.setDonGia(tableRow.getProperty("DonGia").toString());
					item.setURL("http://" + tableRow.getProperty("URL").toString());
					item.setTenLoaiSP(tableRow.getProperty("MaLoaiSP").toString());	
					item.setTenDVT(tableRow.getProperty("MaDVT").toString());					
					result.add(item);		
				}
			}			

		} catch (Exception e) {
			System.out.println(e);
			return null;			
		}
		return result;
	}
	
	public Boolean changPass(String user, String pass) {

		
		Boolean result = false;
		
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"updatePassword");
		
		request.addProperty("username", user);
		request.addProperty("password", pass);
		
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;

		try {
			
			httpTransport.call("http://tempuri.org/updatePassword", envelope);			
			response = envelope.getResponse();	
			int temp = Integer.valueOf(response.toString());
			if(temp == 1)
				result = true;
			else
				result = false;

		} catch (Exception e) {
			System.out.println(e);
			return result;			
		}
		return result;
	}
	
	public Boolean resetPass(String email, String pass) {

		
		Boolean result = false;
		
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"updatePasswordByEmail");
		
		request.addProperty("Email", email);
		request.addProperty("password", pass);
		
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;

		try {
			
			httpTransport.call("http://tempuri.org/updatePasswordByEmail", envelope);			
			response = envelope.getResponse();	
			int temp = Integer.valueOf(response.toString());
			if(temp == 1)
				result = true;
			else
				result = false;

		} catch (Exception e) {
			System.out.println(e);
			return result;			
		}
		return result;
	}
	
	public Boolean addMoney(String maKH, String maThe) {

		
		Boolean result = false;
		
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"setSoTien");
		
		request.addProperty("MaKH", maKH);
		request.addProperty("MaThe", maThe);
		
		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;

		try {
			
			httpTransport.call("http://tempuri.org/setSoTien", envelope);			
			response = envelope.getResponse();	
			int temp = Integer.valueOf(response.toString());
			if(temp == 1)
				result = true;
			else
				result = false;

		} catch (Exception e) {
			System.out.println(e);
			return result;			
		}
		return result;
	}
	
	

	// get list categories
	public List<DanhSachSanPham> getDanhMucSanPham() {

		
		List<DanhSachSanPham> result = new ArrayList<DanhSachSanPham>();
		
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"getDSLoaiSanPham");

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;

		try {
			
			httpTransport.call("http://tempuri.org/getDSLoaiSanPham", envelope);
			response = (SoapObject) envelope.getResponse();
			response = (SoapObject) response.getProperty(1);
			table = (SoapObject) response.getProperty(0);

			slbg = table.getPropertyCount();

			for (int i = 0; i < slbg; i++)
			{
				DanhSachSanPham item = new DanhSachSanPham();				
				tableRow = (SoapObject) table.getProperty(i);
				if(!tableRow.getProperty("TenLoaiSP").toString().equals("Mặc định"))
				{
					item.setMaLoaiSP(tableRow.getProperty("MaLoaiSP").toString());
					item.setTenLoaiSP(tableRow.getProperty("TenLoaiSP").toString());				
					item.setUrl("http://" + tableRow.getProperty("URL").toString());
					result.add(item);
				}
			}
			return result;

		} catch (Exception e) {
			System.out.println(e);
			return null;			
		}
	}	

	// test
	public int updatePass(String username, String password) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"updatePassword");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("username");
		pi.setValue(username);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("password");
		pi.setValue(password);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/updatePassword", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// check soluongton
	public int checkSLTon(String MaSP, String SoLuong) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"checkSoLuongTon");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaSP");
		pi.setValue(MaSP);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("SoLuong");
		pi.setValue(SoLuong);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/checkSoLuongTon", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// set soluongton
	public int setSLTon(String MaSP, String SoLuong) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"setSoLuongTon");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaSP");
		pi.setValue(MaSP);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("SoLuong");
		pi.setValue(SoLuong);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/setSoLuongTon", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// update khachhang
	public int setKhachhang(String MaKH, String HoTen, String DiaChi,
			int DienThoai, String Email, int CMND) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"updateKhachHang");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("HoTen");
		pi.setValue(HoTen);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("DiaChi");
		pi.setValue(DiaChi);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("DienThoai");
		pi.setValue(DienThoai);
		pi.setType(Integer.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("Email");
		pi.setValue(Email);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("CMND");
		pi.setValue(CMND);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/updateKhachHang", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// set maloaikh of khachhang
	public int setMaLoai(String MaKH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"setMaLoaiKH");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/setMaLoaiKH", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// set diemthuong of khachhang
	public int setDiemThuongKH(String MaKH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"setDiemThuong");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/setDiemThuong", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// reset diemthuong of khachhang
	public int resetDiemThuongKH(String MaKH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"resetDiemThuong");

		PropertyInfo pi = new PropertyInfo();
		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/resetDiemThuong", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// get CT_GIOHANG of KHACHHANG by MaGH
	public ArrayList<CT_GioHang> getCTGioHang(int MaGH) {

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"getCTGioHang");

		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;

		try {
			httpTransport.call("http://tempuri.org/getCTGioHang", envelope);
			response = (SoapObject) envelope.getResponse();
			response = (SoapObject) response.getProperty(1);
			table = (SoapObject) response.getProperty(0);
			int slbg;
			slbg = table.getPropertyCount();
			CT_GioHang ct_giohang;
			ct_giohangList = new ArrayList<CT_GioHang>();
			// if (slbg!=0){
			for (int i = 0; i < slbg; i++) {
				ct_giohang = new CT_GioHang();
				tableRow = (SoapObject) table.getProperty(i);
				ct_giohang.setMasp(Integer.valueOf(tableRow.getProperty("MaSP")
						.toString()));
				ct_giohang.setTensp(tableRow.getProperty("TenSP").toString());
				ct_giohang.setSoluong(tableRow.getProperty("SoLuong")
						.toString());
				ct_giohang.setDongia(Double.valueOf(tableRow.getProperty(
						"DonGia").toString()));
				ct_giohangList.add(ct_giohang);
			}
			return ct_giohangList;

		} catch (Exception e) {
			return null;
		}
	}

	// checkout
	public int checkoutGioHang(String MaGH, String MaKH, String SoTien) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE, "checkout");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("SoTien");
		pi.setValue(SoTien);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/checkout", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// update Total of cart
	public String updateTien(String MaGH, String TongTien) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"updateTongTien");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("TongTien");
		pi.setValue(TongTien);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/updateTongTien", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	// update quality of product
	public String updateSoLuong(String MaGH, String MaSP, int SoLuong) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"updateSoLuong");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("MaSP");
		pi.setValue(MaSP);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("SoLuong");
		pi.setValue(SoLuong);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/updateSoLuong", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	// delete item of cart by cart id and product id
	public String deleteCTGioHang(String MaGH, String MaSP) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"deleteCTGioHangByID");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("MaSP");
		pi.setValue(MaSP);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/deleteCTGioHangByID",
					envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	// delete cart without choosing
	public int deleteGioHang(String MaGH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"deleteGioHang");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/deleteGioHang", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// test for cart isCheckout true or false for first login
	public int checkGioHang(int MaKH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"checkGioHang");

		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/checkGioHang", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	public Boolean insertCustomer(KhachHang item) {
		Boolean result = false;

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,"insertKhachHang");
		request.addProperty("TaiKhoan", item.getTaiKhoan());
		request.addProperty("MatKhau", item.getMatKhau());
		request.addProperty("TrangThai", item.getTrangThai());
		request.addProperty("SoTien", 0);
		request.addProperty("DiemThuong", item.getDiemThuong());
		request.addProperty("HoTen", item.getHoTen());
		request.addProperty("DiaChi", item.getDiaChi());
		request.addProperty("DienThoai", item.getDienThoai());
		request.addProperty("Email", item.getEmail());
		request.addProperty("CMND", item.getcMND());

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/insertKhachHang", envelope);
			response = envelope.getResponse();
			int temp = Integer.valueOf(response.toString());
			if(temp == 1)
				result = true;
			else
				result = false;			
		} catch (Exception exception) {
			response = exception.toString();
			result = false;
		}
		return result;
	}

	public KhachHang selectCustomerByUser(String user, String pass) {
		KhachHang item = new KhachHang();

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"getKhachHangByUP");
		request.addProperty("user", user);
		request.addProperty("pass", pass);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;
		envelope.setOutputSoapObject(request);
		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		SoapObject response = null;
		try {
			httpTransport.call("http://tempuri.org/getKhachHangByUP", envelope);
			response = (SoapObject) envelope.getResponse();
			response = (SoapObject) response.getProperty(1);
			table = (SoapObject) response.getProperty(0);
			if (table.getPropertyCount() != 0) {
				tableRow = (SoapObject) table.getProperty(0);
				item.setMakh(Integer.valueOf(tableRow.getProperty("MaKH")
						.toString()));
				item.setTaiKhoan(tableRow.getProperty("TaiKhoan").toString());
				item.setcMND(Integer.valueOf(tableRow.getProperty("CMND")
						.toString()));
				item.setDiaChi(tableRow.getProperty("DiaChi").toString());
				item.setDiemThuong(Integer.valueOf(tableRow.getProperty(
						"DiemThuong").toString()));
				item.setDienThoai(Integer.valueOf(tableRow.getProperty(
						"DienThoai").toString()));
				item.setEmail(tableRow.getProperty("Email").toString());
				item.setHoTen(tableRow.getProperty("HoTen").toString());
				item.setMatKhau(tableRow.getProperty("MatKhau").toString());
				item.setSoTien(Double.valueOf(tableRow.getProperty("SoTien")
						.toString()));
				item.setMaloaitk(Integer.valueOf(tableRow.getProperty(
						"MaLoaiKH").toString()));
				item.setTenloaikh(tableRow.getProperty("TenLoaiKH").toString());
				item.setUudai(tableRow.getProperty("UuDai").toString());
				item.setTrangThai(Integer.valueOf(tableRow.getProperty(
						"TrangThai").toString()));
				return item;
			} else {
				return null;
			}

		} catch (Exception exception) {
			return null;
		}
	}

	// get max ID of GioHang for create next ID of person
	public String getGioHangByID(String MaKH) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"getGioHangByID");

		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/getGioHangByID", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	// get max ID of GioHang for create next ID of person
	public int getGioHangIDMax() {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"getGioHangIDMax");

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/getGioHangIDMax", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return Integer.valueOf(response.toString());
	}

	// insert data to GioHang
	public String insertGioHang(String MaGH, String NgayGH, int TongTien,
			String MaKH, int ThanhToan) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"insertGioHang");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("NgayGH");
		pi.setValue(NgayGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("TongTien");
		pi.setValue(TongTien);
		pi.setType(Integer.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("MaKH");
		pi.setValue(MaKH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("ThanhToan");
		pi.setValue(ThanhToan);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/insertGioHang", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	// insert data to CTGioHang
	public String insertCTGioHang(String MaGH, String MaSP, int SoLuong) {
		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				"insertCTGioHang");
		PropertyInfo pi = new PropertyInfo();
		pi.setName("MaGH");
		pi.setValue(MaGH);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("MaSP");
		pi.setValue(MaSP);
		pi.setType(String.class);
		request.addProperty(pi);

		pi = new PropertyInfo();
		pi.setName("SoLuong");
		pi.setValue(SoLuong);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try {
			httpTransport.call("http://tempuri.org/insertCTGioHang", envelope);
			response = envelope.getResponse();
		} catch (Exception exception) {
			response = exception.toString();
		}
		return response.toString();
	}

	public String Call(int a, int b) {

		SoapObject request = new SoapObject(WSDL_TARGET_NAMESPACE,
				OPERATION_NAME);
		PropertyInfo pi = new PropertyInfo();
		pi.setName("a");
		pi.setValue(a);
		pi.setType(Integer.class);
		request.addProperty(pi);
		pi = new PropertyInfo();
		pi.setName("b");
		pi.setValue(b);
		pi.setType(Integer.class);
		request.addProperty(pi);

		SoapSerializationEnvelope envelope = new SoapSerializationEnvelope(
				SoapEnvelope.VER11);
		envelope.dotNet = true;

		envelope.setOutputSoapObject(request);

		HttpTransportSE httpTransport = new HttpTransportSE(SOAP_ADDRESS);
		Object response = null;
		try

		{

			httpTransport.call(SOAP_ACTION, envelope);

			response = envelope.getResponse();

		}

		catch (Exception exception)

		{

			response = exception.toString();

		}

		return response.toString();
	}

}
